//
//  BoostCollectionViewCell.m
//  u76ho
//
//  Created by m-air-01 on 16/2/19.
//  Copyright © 2016年 LV. All rights reserved.
//

#import "BoostCollectionViewCell.h"
@interface BoostCollectionViewCell ()<UIScrollViewDelegate>
{
    CGFloat lastScale;
    UIImageView * imgV;
}
@end
@implementation BoostCollectionViewCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)setPath:(NSString *)path
{
    for (id i in self.subviews) {
        [i removeFromSuperview];
    }
    NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",U76HOURL,path]];
    UIScrollView * scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
    
    //scrollV.backgroundColor = [UIColor greenColor];
    scrollV.delegate = self;
    [self addSubview:scrollV];
    imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
    [imgV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@""]];
    imgV.userInteractionEnabled = YES;
    NSLog(@"====%f",imgV.image.size.width);
    NSLog(@"----%f",imgV.image.size.height);
    imgV.contentMode = UIViewContentModeScaleAspectFit;
    
    [scrollV addSubview:imgV];
    if (imgV.image.size.width != 0) {
        imgV.frame = CGRectMake(0,(self.height - imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width))/2, SCREEN_WIDTH, imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width));
    }
    
    NSLog(@"******%f",imgV.frame.size.height);
    scrollV.contentSize = CGSizeMake(SCREEN_WIDTH, imgV.frame.size.height);
    
    //设置实现缩放
    scrollV.maximumZoomScale = 2.0;
    scrollV.minimumZoomScale = 1.0;
    scrollV.bounces = NO;
    
    
    UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    tapGesture.numberOfTapsRequired = 1;
    tapGesture.numberOfTouchesRequired = 1;
    [imgV addGestureRecognizer:tapGesture];
    
}
-(void)tapAction:(UITapGestureRecognizer *)tap
{
//    NSLog(@"图片被点击了 ***");
    [self.delegate celldelegate];
}
-(void)setImg:(UIImage *)img
{
    for (id i in self.subviews) {
        [i removeFromSuperview];
    }
    UIScrollView * scrollV = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
    scrollV.delegate = self;
    [self addSubview:scrollV];
    imgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.height)];
   // imgV.backgroundColor = [UIColor redColor];

    
    imgV.image = img;
    imgV.userInteractionEnabled = YES;
    NSLog(@"====%f",imgV.image.size.width);
    NSLog(@"----%f",imgV.image.size.height);
    imgV.contentMode = UIViewContentModeScaleAspectFit;
    
    [scrollV addSubview:imgV];
    if (imgV.image.size.width != 0) {
        imgV.frame = CGRectMake(0,(self.height - imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width))/2, SCREEN_WIDTH, imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width));
    }
    
    NSLog(@"******%f",imgV.frame.size.height);
    scrollV.contentSize = CGSizeMake(SCREEN_WIDTH, imgV.frame.size.height);
    
    //设置实现缩放
    scrollV.maximumZoomScale = 2.0;
    scrollV.minimumZoomScale = 1.0;
    scrollV.bounces = NO;

}
-(void)setContenStr:(NSString *)contenStr
{
    CGFloat height = [contenStr heightOfSize:18 width:SCREEN_WIDTH - SIZETO6W(20)*2];
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, self.height- height-SIZETO6H(20), SCREEN_WIDTH, height+SIZETO6H(20))];
    bgView.backgroundColor = [UIColor blackColor];
    bgView.alpha = 0.5;
    [self addSubview:bgView];
    
    UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(SIZETO6W(20), 0, SCREEN_WIDTH - SIZETO6W(20)*2, bgView.height)];
    lab.text = contenStr;
    lab.numberOfLines = 0;
    lab.font = [UIFont systemFontOfSize:16];
    lab.textColor = [UIColor whiteColor];
    [bgView addSubview:lab];
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imgV;
}
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    CGFloat scale = scrollView.zoomScale;
    NSLog(@"Scale%f",scale);
    if (imgV.image.size.width != 0) {

        imgV.frame = CGRectMake(0,(self.height - scale * imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width))/2 > 0 ? (self.height - scale * imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width))/2 : 0, SCREEN_WIDTH*scale, scale * imgV.image.size.height*(SCREEN_WIDTH / imgV.image.size.width));
    }
    
}
@end
